<%-- 
    Document   : grammars
    Created on : May 29, 2012, 11:25:46 AM
    Author     : Eldred
--%>

<%@page import="java.io.Writer"%>
<%@page import="cz.muni.fi.pb138.srgsxmldb.manager.XManager"%>
<%@page import="cz.muni.fi.pb138.srgsxmldb.manager.IXManager"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>

<div class ="list">
    
    <%
        IXManager manager = new XManager();
        String[] grams = (String[]) request.getAttribute("grams");
        String root = (String) request.getAttribute("root");
    %>
    <h2>Search database by grammar root element:</h2>
    <form class="input" action="SearchServlet" method="post">
        <input name="root" type="text" />
        <input name="search" class="submit" type="submit" value="Search" />
    </form>
    
    <%
        if (root == null) {
             
            out.write("<h3>All grammars from database:</h3>");
        }
        else {
            
            out.write("<h3>Grammas containing root "+root+":</h3>");
        }
    %> 
    

        <table class="grammars" border="0">  
                <tr><th width="150">file name</th><th>root element</th><th>download as XML</th><th>download as JSGF</th><th>delete from database</th></tr>
    <%    
        if(grams!=null)
        for(String name : grams) {
    %>
    <tr>
        <td><% out.write(name); %></td>
        <td><% out.write(manager.getGrammarRootByFileName(name)); %></td>
        <td class="center"><a href="<c:url value="/Download"/>?file=<%out.write(name);%>" title="Download XML File">
            <img src="css/download_xml.png" alt="Download XML File"/></a></td>
        <td class="center"><a href="<c:url value="/DownloadJSGF"/>?file=<%out.write(name);%>" title="Download as JSGF">
            <img src="css/download_jsgf.png" alt="Download as JSGF"/></a></td>
        <td class="center"><a href="<c:url value="/DeleteServlet"/>?file=<%out.write(name);%>" title="Delete Grammar">
            <img src="css/delete.png" alt="Delete Grammar"/></a></td>
    </tr>
    <%
        }
    %> 
        </table>
</div>
